{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Strong Password Checker II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: strongPasswordCheckerII"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #强密码检验器 II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>如果一个密码满足以下所有条件，我们称它是一个 <strong>强</strong>&nbsp;密码：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>它有至少 <code>8</code>&nbsp;个字符。</li>\n",
    "\t<li>至少包含 <strong>一个小写英文</strong>&nbsp;字母。</li>\n",
    "\t<li>至少包含 <strong>一个大写英文</strong>&nbsp;字母。</li>\n",
    "\t<li>至少包含 <strong>一个数字</strong>&nbsp;。</li>\n",
    "\t<li>至少包含 <strong>一个特殊字符</strong>&nbsp;。特殊字符为：<code>\"!@#$%^&amp;*()-+\"</code>&nbsp;中的一个。</li>\n",
    "\t<li>它 <strong>不</strong>&nbsp;包含&nbsp;<code>2</code>&nbsp;个连续相同的字符（比方说&nbsp;<code>\"aab\"</code>&nbsp;不符合该条件，但是&nbsp;<code>\"aba\"</code>&nbsp;符合该条件）。</li>\n",
    "</ul>\n",
    "\n",
    "<p>给你一个字符串&nbsp;<code>password</code>&nbsp;，如果它是一个&nbsp;<strong>强</strong>&nbsp;密码，返回&nbsp;<code>true</code>，否则返回&nbsp;<code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>password = \"IloveLe3tcode!\"\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>密码满足所有的要求，所以我们返回 true 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>password = \"Me+You--IsMyDream\"\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>密码不包含数字，且包含 2 个连续相同的字符。所以我们返回 false 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>password = \"1aB!\"\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>密码不符合长度要求。所以我们返回 false 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= password.length &lt;= 100</code></li>\n",
    "\t<li><code>password</code>&nbsp;包含字母，数字和&nbsp;<code>\"!@#$%^&amp;*()-+\"</code>&nbsp;这些特殊字符。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [strong-password-checker-ii](https://leetcode.cn/problems/strong-password-checker-ii/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [strong-password-checker-ii](https://leetcode.cn/problems/strong-password-checker-ii/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"IloveLe3tcode!\"', '\"Me+You--IsMyDream\"', '\"1aB!\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        if all(not w.islower() for w in password):\n",
    "            return False\n",
    "        if all(not w.isupper() for w in password):\n",
    "            return False\n",
    "\n",
    "        if all(not w.isnumeric() for w in password):\n",
    "            return False\n",
    "        if all(w not in \"!@#$%^&*()-+\" for w in password):\n",
    "            return False\n",
    "        n = len(password)\n",
    "        return all(password[i+1]!=password[i] for i in range(n-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        pattern = r\"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()\\-+])[a-zA-Z\\d!@#$%^&*()\\-+]{8,}$\"\n",
    "        if re.match(pattern, password):\n",
    "        # 检查是否包含2个连续相同的字符\n",
    "            for i in range(len(password) - 1):\n",
    "                if password[i] == password[i + 1]:\n",
    "                    return False\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        l = [0, 0, 0, 0]\n",
    "        for i in range(len(password)):\n",
    "            if i < len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                l[2] += 1\n",
    "            if ord('a') <= ord(password[i]) <= ord('z'):\n",
    "                l[1] += 1\n",
    "            if ord('A') <= ord(password[i]) <= ord('Z'):\n",
    "                l[0] += 1\n",
    "            if ord('0') <= ord(password[i]) <= ord('9'):\n",
    "                l[3] += 1\n",
    "        print(l)\n",
    "        return l[0] * l[1] * l[2] * l[3] > 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "#         diclower = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "#         dicupper = diclower.upper()\n",
    "#         dicnum = \"1234567890\"\n",
    "#         dicspecial = \"!@#$%^&*()-+\"\n",
    "#         def check(dic, i):\n",
    "#             for j in dic:\n",
    "#                 if j in i:\n",
    "#                     return True\n",
    "#         def doublecheck(i):\n",
    "#             for n in range(len(i)-1):\n",
    "#                 if i[n] == i[n+1]:\n",
    "#                     return False\n",
    "#             return True\n",
    "#         if len(password)>=8 and check(diclower, password) and check(dicupper, password) and check(dicnum, password) and check(dicspecial, password) and doublecheck(password):\n",
    "#             return True\n",
    "#         else:\n",
    "#             return False\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        special_s = '!@#$%^&*()-+'\n",
    "        n = len(password)\n",
    "        if n < 8: return False\n",
    "        flag1, flag2, flag3, flag4 = False, False, False, False\n",
    "        for i in range(n):\n",
    "            if 'a' <= password[i] <= 'z':\n",
    "                flag1 = True\n",
    "            elif 'A' <= password[i] <= 'Z':\n",
    "                flag2 = True\n",
    "            elif '0' <= password[i] <= '9':\n",
    "                flag3 = True\n",
    "            elif password[i] in special_s:\n",
    "                flag4 = True\n",
    "            if i and password[i] == password[i-1]:\n",
    "                return False\n",
    "        return flag1 and flag2 and flag3 and flag4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        res = [0]*6\n",
    "        if len(password)<8:res[0] = 0\n",
    "        else:res[0] = 1\n",
    "        albet = \"!@#$%^&*()-+\"\n",
    "        for i in range(len(password)):\n",
    "            if password[i].islower():res[1] = 1\n",
    "            elif password[i].isupper():res[2] = 1\n",
    "            elif password[i].isalnum():res[3] = 1\n",
    "            elif password[i] in albet:res[4] = 1\n",
    "        for i in range(1,len(password)):\n",
    "            if password[i-1]==password[i]:\n",
    "                return False\n",
    "            else:res[5] = 1\n",
    "        return sum(res) == 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        mask = 0\n",
    "        for i, c in enumerate(password):\n",
    "            if i and c == password[i - 1]:\n",
    "                return False\n",
    "            if c.islower():\n",
    "                mask |= 1\n",
    "            elif c.isupper():\n",
    "                mask |= 2\n",
    "            elif c.isdigit():\n",
    "                mask |= 4\n",
    "            else:\n",
    "                mask |= 8\n",
    "        return mask == 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, p: str) -> bool:\n",
    "        if len(p)<8: \n",
    "            return False\n",
    "        a = [0,0,0,0,1]\n",
    "        for ch in p:\n",
    "            if 'a'<=ch<='z':\n",
    "                a[0]=1\n",
    "            if 'A'<=ch<='Z':\n",
    "                a[1]=1\n",
    "            if '0'<=ch<='9':\n",
    "                a[2]=1\n",
    "            if ch in '!@#$%^&*()-+':\n",
    "               a[3]=1\n",
    "        i = 0 \n",
    "        while i<len(p)-1:\n",
    "            if p[i]==p[i+1]: a[4]=0\n",
    "            i += 1\n",
    "        # print(a)\n",
    "        return sum(a)==5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if(len(password)<8):\n",
    "            return False\n",
    "        for i in range(len(password)-1):\n",
    "            if(password[i] == password[i+1]):\n",
    "                return False\n",
    "        lowercase = set('qazwsxedcrfvtgbyhnujmikolp')\n",
    "        upercase = set('QAZWSXEDCRFVTGBYHNUJMIKOLP')\n",
    "        num = set('1234567890')\n",
    "        char = set('!@#$%^&*()-+')\n",
    "        password = set(password)\n",
    "        if not(password & lowercase):\n",
    "            return False\n",
    "        if not(password & upercase):\n",
    "            return False\n",
    "        if not(password & num):\n",
    "            return False\n",
    "        if not(password & char):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        pattern = r\"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()\\-+])[a-zA-Z\\d!@#$%^&*()\\-+]{8,}$\"\n",
    "        if re.match(pattern, password):\n",
    "        # 检查是否包含2个连续相同的字符\n",
    "            for i in range(len(password) - 1):\n",
    "                if password[i] == password[i + 1]:\n",
    "                    return False\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, p: str) -> bool:\n",
    "        if len(p)<8: return False\n",
    "        a = [0,0,0,0,1]\n",
    "        for ch in p:\n",
    "            if 'a'<=ch<='z': a[0]=1\n",
    "            if 'A'<=ch<='Z': a[1]=1\n",
    "            if '0'<=ch<='9': a[2]=1\n",
    "            if ch in '!@#$%^&*()-+': a[3]=1\n",
    "        i = 0 \n",
    "        while i<len(p)-1:\n",
    "            if p[i]==p[i+1]: a[4]=0\n",
    "            i += 1\n",
    "        # print(a)\n",
    "        return sum(a)==5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        low_mark=False\n",
    "        up_mark=False\n",
    "        int_mark=False\n",
    "        set_mark=False\n",
    "        str_set=\"!@#$%^&*()-+\"\n",
    "        for i in range(n):\n",
    "            if i-1 >= 0 and password[i] == password[i-1]: return False\n",
    "            elif password[i].islower():low_mark=True\n",
    "            elif password[i].isupper():up_mark=True\n",
    "            elif password[i].isdigit():int_mark=True\n",
    "            elif password[i] in str_set:set_mark=True\n",
    "        return low_mark&up_mark&int_mark&set_mark\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        \n",
    "        specials = set(\"!@#$%^&*()-+\")\n",
    "        hasLower = hasUpper = hasDigit = hasSpecial = False\n",
    "\n",
    "        for i, ch in enumerate(password):\n",
    "            if i != len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "\n",
    "            if ch.islower():\n",
    "                hasLower = True\n",
    "            elif ch.isupper():\n",
    "                hasUpper = True\n",
    "            elif ch.isdigit():\n",
    "                hasDigit = True\n",
    "            elif ch in specials:\n",
    "                hasSpecial = True\n",
    "\n",
    "        return hasLower and hasUpper and hasDigit and hasSpecial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if(len(password)<8):\n",
    "            return False\n",
    "        for i in range(len(password)-1):\n",
    "            if(password[i] == password[i+1]):\n",
    "                return False\n",
    "        lowercase = set('qazwsxedcrfvtgbyhnujmikolp')\n",
    "        upercase = set('QAZWSXEDCRFVTGBYHNUJMIKOLP')\n",
    "        num = set('1234567890')\n",
    "        char = set('!@#$%^&*()-+')\n",
    "        password = set(password)\n",
    "        if not(password & lowercase):\n",
    "            return False\n",
    "        if not(password & upercase):\n",
    "            return False\n",
    "        if not(password & num):\n",
    "            return False\n",
    "        if not(password & char):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if (len(password) < 8 or \n",
    "            all(not c.islower() for c in password) or \n",
    "            all(not c.islower() for c in password) or \n",
    "            all(not c.isupper() for c in password) or \n",
    "            all(not c.isdigit()  for c in password) or \n",
    "            all(c not in set(\"!@#$%^&*()-+\") for c in password) or \n",
    "            any(password[i] == password[i+1] for i in range(len(password)-1))):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        for i in range(1,len(password)):\n",
    "            if password[i] == password[i-1]:\n",
    "                return False\n",
    "        f1,f2,f3,f4 = False,False,False,False\n",
    "        for i in range(len(password)):\n",
    "            if ord(password[i]) >= 65 and ord(password[i]) <= 90:\n",
    "                f1 = True\n",
    "            if ord(password[i]) >= 97 and ord(password[i]) <= 122:\n",
    "                f2 = True\n",
    "            if password[i] in '0123456789':\n",
    "                f3 = True\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                f4 = True\n",
    "        return f1&f2&f3&f4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        SpeChar = '!@#$%^&*()-+'\n",
    "        islower = False\n",
    "        isUpper = False\n",
    "        isDigit = False\n",
    "        isSpecial = False\n",
    "        preChar = password[1]\n",
    "        for i in password:\n",
    "            if i == preChar:\n",
    "                return False\n",
    "            preChar = i\n",
    "            if i.islower():\n",
    "                islower = True\n",
    "            elif i.isupper():\n",
    "                isUpper = True\n",
    "            elif i.isdigit():\n",
    "                isDigit = True\n",
    "            elif i in SpeChar:\n",
    "                isSpecial = True\n",
    "        return islower and isUpper and isDigit and isSpecial\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        \n",
    "        specials = set(\"!@#$%^&*()-+\")\n",
    "        hasLower = hasUpper = hasDigit = hasSpecial = False\n",
    "\n",
    "        for i, ch in enumerate(password):\n",
    "            if i != len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "\n",
    "            if ch.islower():\n",
    "                hasLower = True\n",
    "            elif ch.isupper():\n",
    "                hasUpper = True\n",
    "            elif ch.isdigit():\n",
    "                hasDigit = True\n",
    "            elif ch in specials:\n",
    "                hasSpecial = True\n",
    "\n",
    "        return hasLower and hasUpper and hasDigit and hasSpecial\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        x,y,z,a = 0,0,0,0\n",
    "        l1 = {\"!\",\"@\",\"#\",\"$\",\"%\",\"^\",\"&\",\"*\",\"(\",\")\",\"-\",\"+\"}\n",
    "        for i in range (len(password) - 1):\n",
    "            if password[i].islower():\n",
    "                x += 1\n",
    "            if password[i].isupper():\n",
    "                y += 1\n",
    "            if password[i].isdigit():\n",
    "                z += 1\n",
    "            if password[i] in l1:\n",
    "                a += 1\n",
    "            if password[i] == password[i + 1]:\n",
    "                return False\n",
    "        if password[-1].islower():\n",
    "            x += 1\n",
    "        if password[-1].isupper():\n",
    "            y += 1\n",
    "        if password[-1].isdigit():\n",
    "            z += 1\n",
    "        if password[-1] in l1:\n",
    "            a += 1\n",
    "        if x * y * z * a == 0:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8: return False\n",
    "        letter_upper = False\n",
    "        letter_lower = False\n",
    "        digit = False\n",
    "        special = False\n",
    "        specials = '!@#$%^&*()-+'\n",
    "        tmp = ''\n",
    "        for word in password:\n",
    "            if tmp == '':\n",
    "                tmp = word\n",
    "            else:\n",
    "                if tmp == word:\n",
    "                    return False\n",
    "                else:\n",
    "                    tmp = word\n",
    "            if word.isupper(): \n",
    "                letter_upper = True\n",
    "                continue\n",
    "            elif word.islower():\n",
    "                letter_lower = True\n",
    "                continue\n",
    "            elif word.isdigit():\n",
    "                digit = True\n",
    "                continue\n",
    "            elif word in specials:\n",
    "                special = True\n",
    "        return True if letter_upper and letter_lower and digit and special else False\n",
    "\n",
    "             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        x,y,z,a = 0,0,0,0\n",
    "        l1 = {\"!\",\"@\",\"#\",\"$\",\"%\",\"^\",\"&\",\"*\",\"(\",\")\",\"-\",\"+\"}\n",
    "        for i in range (len(password) - 1):\n",
    "            if password[i].islower():\n",
    "                x += 1\n",
    "            if password[i].isupper():\n",
    "                y += 1\n",
    "            if password[i].isdigit():\n",
    "                z += 1\n",
    "            if password[i] in l1:\n",
    "                a += 1\n",
    "            if password[i] == password[i + 1]:\n",
    "                return False\n",
    "        if password[-1].islower():\n",
    "            x += 1\n",
    "        if password[-1].isupper():\n",
    "            y += 1\n",
    "        if password[-1].isdigit():\n",
    "            z += 1\n",
    "        if password[-1] in l1:\n",
    "            a += 1\n",
    "        if x * y * z * a == 0:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "\n",
    "        if n<8:\n",
    "            return False\n",
    "        \n",
    "        judge1 = [password[i].isupper() for i in range(n)]\n",
    "        if any(judge1)==False:\n",
    "            return False\n",
    "        \n",
    "        judge2 = [password[i].islower() for i in range(n)]\n",
    "        if any(judge2)==False:\n",
    "            return False\n",
    "        \n",
    "        judge3 = [password[i].isnumeric() for i in range(n)]\n",
    "        if any(judge3)==False:\n",
    "            return False\n",
    "        \n",
    "        secret = \"!@#$%^&*()-+\"\n",
    "\n",
    "        judge4 = [password[i] in secret for i in range(n)]\n",
    "        if any(judge4)==False:\n",
    "            return False\n",
    "        \n",
    "        for i in range(1,n):\n",
    "            if password[i-1] == password[i]:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        password = list(password)\n",
    "        small = 0\n",
    "        upper = 0\n",
    "        num = 0\n",
    "        repeat = 0\n",
    "        unique = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+']\n",
    "        uni = 0\n",
    "        if len(password) >= 8:\n",
    "            for i in password:\n",
    "                if ord(i) in range(65, 91):\n",
    "                    upper += 1\n",
    "                if ord(i) in range(97, 123):\n",
    "                    small += 1\n",
    "                if ord(i) in range(48, 58):\n",
    "                    num += 1\n",
    "                if i != password[-1] and i == password[password.index(i)+1]:\n",
    "                    repeat += 1\n",
    "                if i in unique:\n",
    "                    uni += 1\n",
    "        if small >= 1 and upper >= 1 and num >= 1 and repeat == 0 and uni >= 1:\n",
    "            return True\n",
    "\n",
    "        return False\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        small_e = False\n",
    "        big_e = False\n",
    "        num = False\n",
    "        special = False\n",
    "        last = ''\n",
    "        for c in password:\n",
    "            if  c.isdigit():\n",
    "                num = True\n",
    "            elif c.islower():\n",
    "                small_e = True\n",
    "            elif c.isupper():\n",
    "                big_e = True\n",
    "            elif c in \"!@#$%^&*()-+\":\n",
    "                special = True\n",
    "            if last == c:\n",
    "                return False\n",
    "            last = c\n",
    "        return num and small_e and big_e and special"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        l = [0, 0, 0, 0]\n",
    "        for i in range(len(password)):\n",
    "            if i < len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                l[2] += 1\n",
    "            if ord('a') <= ord(password[i]) <= ord('z'):\n",
    "                l[1] += 1\n",
    "            if ord('A') <= ord(password[i]) <= ord('Z'):\n",
    "                l[0] += 1\n",
    "            if ord('0') <= ord(password[i]) <= ord('9'):\n",
    "                l[3] += 1\n",
    "        print(l)\n",
    "        return l[0] * l[1] * l[2] * l[3] > 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        \n",
    "        specials = set(\"!@#$%^&*()-+\")\n",
    "        hasLower = hasUpper = hasDigit = hasSpecial = False\n",
    "\n",
    "        for i, ch in enumerate(password):\n",
    "            if i != len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "\n",
    "            if ch.islower():\n",
    "                hasLower = True\n",
    "            elif ch.isupper():\n",
    "                hasUpper = True\n",
    "            elif ch.isdigit():\n",
    "                hasDigit = True\n",
    "            elif ch in specials:\n",
    "                hasSpecial = True\n",
    "\n",
    "        return hasLower and hasUpper and hasDigit and hasSpecial\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) >= 8 and password.upper()!=password and password.lower()!=password:\n",
    "          sign1 = False\n",
    "          sign2 = False\n",
    "          for i in password:\n",
    "              if i in [str(l) for l in range(0,10)]:\n",
    "                  sign1  = True\n",
    "              if i in \"!@#$%^&*()-+\":\n",
    "                  sign2  = True\n",
    "              if sign1 and sign2:break\n",
    "          print(sign1,sign2)\n",
    "          if sign1 and sign2:\n",
    "              for j in range(1,len(password)):\n",
    "                    if password[j] == password[j-1]:\n",
    "                        return False\n",
    "              return True;\n",
    "          else:\n",
    "              return False\n",
    "          \n",
    "                  \n",
    "        else:\n",
    "            return False  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        lowerCnt = upperCnt = digitCnt = sepCnt = 0\n",
    "        speStr = '!@#$%^&*()-+'\n",
    "        pre = ''\n",
    "        preCnt = 0\n",
    "        for c in password:\n",
    "            if c == pre:\n",
    "                preCnt += 1\n",
    "                if preCnt >= 2:\n",
    "                    return False\n",
    "            pre = c\n",
    "            preCnt = 1\n",
    "            if c.islower():\n",
    "                lowerCnt += 1\n",
    "            elif c.isupper():\n",
    "                upperCnt += 1\n",
    "            elif c.isdigit():\n",
    "                digitCnt += 1\n",
    "            elif c in speStr:\n",
    "                sepCnt += 1\n",
    "        return lowerCnt >= 1 and upperCnt >= 1 and digitCnt >= 1 and sepCnt >= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        l = [0, 0, 0, 0]\n",
    "        for i in range(len(password)):\n",
    "            if i < len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                l[2] += 1\n",
    "            if ord('a') <= ord(password[i]) <= ord('z'):\n",
    "                l[1] += 1\n",
    "            if ord('A') <= ord(password[i]) <= ord('Z'):\n",
    "                l[0] += 1\n",
    "            if ord('0') <= ord(password[i]) <= ord('9'):\n",
    "                l[3] += 1\n",
    "        print(l)\n",
    "        return l[0] * l[1] * l[2] * l[3] > 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        xiao = 0\n",
    "        da = 0\n",
    "        num = 0\n",
    "        s = 0\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        for i in password:\n",
    "            if xiao == 0 and 'a' <= i <= 'z':\n",
    "                xiao = 1\n",
    "            if da == 0 and 'A' <= i <= 'Z':\n",
    "                da = 1\n",
    "            if num == 0 and '0' <= i <= '9':\n",
    "                num = 1\n",
    "            if s == 0 and i in \"!@#$%^&*()-+\":\n",
    "                s = 1\n",
    "        for i in range(len(password)-1):\n",
    "            if password[i] == password[i+1]:\n",
    "                return False\n",
    "        if xiao ==1 and da == 1 and num == 1 and s == 1:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        s = set(password)\n",
    "        if not s & set(string.ascii_lowercase):\n",
    "            return False\n",
    "        if not s & set(string.ascii_uppercase):\n",
    "            return False\n",
    "        if not s & set(string.digits):\n",
    "            return False\n",
    "        if not s & set(\"!@#$%^&*()-+\"):\n",
    "            return False\n",
    "        for i in range(1, n):\n",
    "            if password[i] == password[i-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        return  bool(len(password) >= 8 and\n",
    "                search(r'\\d', password) and\n",
    "                search(r'[a-z]', password) and\n",
    "                search(r'[A-Z]', password) and\n",
    "                search(r'[-!@#$%^&*()+]', password) and\n",
    "                not search(r'(.)\\1', password))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        diclower = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "        dicupper = diclower.upper()\n",
    "        dicnum = \"1234567890\"\n",
    "        dicspecial = \"!@#$%^&*()-+\"\n",
    "        def check(dic, i):\n",
    "            for j in dic:\n",
    "                if j in i:\n",
    "                    return True\n",
    "        def doublecheck(i):\n",
    "            for n in range(len(i)-1):\n",
    "                if i[n] == i[n+1]:\n",
    "                    return False\n",
    "            return True\n",
    "        if len(password)>=8 and check(diclower, password) and check(dicupper, password) and check(dicnum, password) and check(dicspecial, password) and doublecheck(password):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, p: str) -> bool:\n",
    "        if len(p) < 8:\n",
    "            return False\n",
    "        smallFlag = False\n",
    "        bigFlag = False\n",
    "        numFlag = False\n",
    "        sFlag = False\n",
    "        for i, pi in enumerate(p):\n",
    "            if \"Z\" >= pi >= \"A\":\n",
    "                bigFlag = True\n",
    "            if \"z\" >= pi >= \"a\":\n",
    "                smallFlag = True\n",
    "            if \"9\" >= pi >= \"0\":\n",
    "                numFlag = True\n",
    "            if pi in \"!@#$%^&*()-+\":\n",
    "                sFlag = True\n",
    "            if i > 0 and p[i] == p[i - 1]:\n",
    "                return False\n",
    "        return smallFlag and bigFlag and numFlag and sFlag\n",
    "                \n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        x=\"!@#$%^&*()-+\"\n",
    "        y='0123456789'\n",
    "        a=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n",
    "        b=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\n",
    "        return len(password)>=8 and any(i in x for i in password) and any(j in y for j in password) and any(i in a for i in password) and any (j in b for j in password) and all(password[i]!=password[i+1] for i in range(len(password)-1))\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        return  bool(len(password) >= 8 and\n",
    "                search(r'\\d', password) and\n",
    "                search(r'[a-z]', password) and\n",
    "                search(r'[A-Z]', password) and\n",
    "                search(r'[!@#$%^&*()\\-+]', password) and\n",
    "                not search(r'(.)\\1', password))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        sp='!@#$%^&*()-+'\n",
    "        flaglower=False\n",
    "        flagupper=False\n",
    "        flagdigit=False\n",
    "        flagspecial=False\n",
    "        flagtwo=True\n",
    "        for i in range(len(password)):\n",
    "            if password[i].islower():\n",
    "                flaglower=True\n",
    "            if password[i].isupper():\n",
    "                flagupper=True\n",
    "            if password[i].isdigit():\n",
    "                flagdigit=True\n",
    "            if password[i] in sp:\n",
    "                flagspecial=True\n",
    "            if i+1<len(password) and password[i]==password[i+1]:\n",
    "                flagtwo=False\n",
    "        flag=flaglower and flagupper and flagdigit and flagspecial and flagtwo and len(password)>=8\n",
    "        if flag:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        mask = 0\n",
    "        for i, c in enumerate(password):\n",
    "            if i and c == password[i - 1]:\n",
    "                return False\n",
    "            if c.islower():\n",
    "                mask |= 1\n",
    "            elif c.isupper():\n",
    "                mask |= 2\n",
    "            elif c.isdigit():\n",
    "                mask |= 4\n",
    "            else:\n",
    "                mask |= 8\n",
    "        return mask == 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "char = list(\"!@#$%^&*()-+\")\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        fo, ft, fs, ff, prev = False, False, False, False, password[1]\n",
    "        for s in password:\n",
    "            if prev == s:\n",
    "                return False\n",
    "            prev = s\n",
    "            if s.isupper():\n",
    "                fo = True\n",
    "            elif s.islower():\n",
    "                ft = True\n",
    "            elif ord(s) >= ord(\"0\") and ord(s) <= ord(\"9\"):\n",
    "                fs = True\n",
    "            elif s in char:\n",
    "                ff = True\n",
    "            \n",
    "        return fo and ft and fs and ff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "      if len(password) < 8:\n",
    "        return False\n",
    "      flag_lower = False\n",
    "      flag_upper = False\n",
    "      flag_one_digit = False\n",
    "      flag_special = False\n",
    "      flag_adjacent = True\n",
    "\n",
    "      for i in range(len(password)):\n",
    "        if password[i].islower():\n",
    "          flag_lower = True\n",
    "\n",
    "        if password[i].isupper():\n",
    "          flag_upper = True\n",
    "        \n",
    "        if password[i].isdigit():\n",
    "          flag_one_digit = True\n",
    "        \n",
    "        if not password[i].isdigit() and not password[i].isalpha():\n",
    "          flag_special = True\n",
    "        \n",
    "      for i in range(len(password) - 1):\n",
    "        if password[i] == password[i + 1]:\n",
    "          flag_adjacent = False\n",
    "        \n",
    "      return flag_lower and flag_upper and flag_one_digit and flag_special and flag_adjacent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "#         diclower = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "#         dicupper = diclower.upper()\n",
    "#         dicnum = \"1234567890\"\n",
    "#         dicspecial = \"!@#$%^&*()-+\"\n",
    "#         def check(dic, i):\n",
    "#             for j in dic:\n",
    "#                 if j in i:\n",
    "#                     return True\n",
    "#         def doublecheck(i):\n",
    "#             for n in range(len(i)-1):\n",
    "#                 if i[n] == i[n+1]:\n",
    "#                     return False\n",
    "#             return True\n",
    "#         if len(password)>=8 and check(diclower, password) and check(dicupper, password) and check(dicnum, password) and check(dicspecial, password) and doublecheck(password):\n",
    "#             return True\n",
    "#         else:\n",
    "#             return False\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        special_s = '!@#$%^&*()-+'\n",
    "        n = len(password)\n",
    "        if n < 8: return False\n",
    "        flag1, flag2, flag3, flag4 = False, False, False, False\n",
    "        for i in range(n):\n",
    "            if 'a' <= password[i] <= 'z':\n",
    "                flag1 = True\n",
    "            elif 'A' <= password[i] <= 'Z':\n",
    "                flag2 = True\n",
    "            elif '0' <= password[i] <= '9':\n",
    "                flag3 = True\n",
    "            elif password[i] in special_s:\n",
    "                flag4 = True\n",
    "            if i and password[i] == password[i-1]:\n",
    "                return False\n",
    "        return flag1 and flag2 and flag3 and flag4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        l = [0, 0, 0, 0]\n",
    "        for i in range(len(password)):\n",
    "            if i < len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                l[2] += 1\n",
    "            if ord('a') <= ord(password[i]) <= ord('z'):\n",
    "                l[1] += 1\n",
    "            if ord('A') <= ord(password[i]) <= ord('Z'):\n",
    "                l[0] += 1\n",
    "            if ord('0') <= ord(password[i]) <= ord('9'):\n",
    "                l[3] += 1\n",
    "        return l[0] * l[1] * l[2] * l[3] > 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        have_uppper=False\n",
    "        have_lower=False\n",
    "        have_digit=False\n",
    "        have_sign=False\n",
    "        if len(password)<8:\n",
    "            return False\n",
    "        last=chr(ord(password[0])-1)\n",
    "        for s in password:\n",
    "            if s==last:\n",
    "                return False\n",
    "            elif s.isdigit():\n",
    "                have_digit=True\n",
    "            elif s in \"!@#$%^&*()-+\":\n",
    "                have_sign=True\n",
    "            elif s.islower():\n",
    "                have_lower=True\n",
    "            elif s.isupper():\n",
    "                have_uppper=True\n",
    "            last=s\n",
    "        return have_digit and have_lower and have_sign and have_uppper\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        special_pass = '!@#$%^&*()-+'\n",
    "        leng = len(password)\n",
    "        if leng < 8:\n",
    "            return False\n",
    "        flag1, flag2, flag3, flag4 = False, False, False, False\n",
    "        for i in range(leng):\n",
    "            if password[i].isupper():\n",
    "                flag1 = True\n",
    "            if password[i].islower():\n",
    "                flag2 = True\n",
    "            if password[i].isdigit():\n",
    "                flag3 = True\n",
    "            if password[i] in special_pass:\n",
    "                flag4 = True\n",
    "            if i and password[i] == password[i-1]:\n",
    "                return False\n",
    "        return flag1 and flag2 and flag3 and flag4\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        chars = \"!@#$%^&*()-+\"\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        a, b, c, d = False, False, False, False\n",
    "        for i in range(n):\n",
    "            if i > 0 and password[i] == password[i - 1]:\n",
    "                return False\n",
    "            if password[i].islower():\n",
    "                a = True\n",
    "            elif password[i].isupper():\n",
    "                b = True\n",
    "            elif password[i].isdigit():\n",
    "                c = True\n",
    "            elif password[i] in chars:\n",
    "                d = True\n",
    "        # if a == 0 or b == 0 or c == 0 or d == 0:\n",
    "        #     return False\n",
    "        return a and b and c and d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "\n",
    "        specials = set('!@#$%^&*()-+')\n",
    "        hasLower = hasUpper = hasDigit = hasSpecial = False\n",
    "\n",
    "        for i, ch in enumerate(password):\n",
    "            if i != len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            \n",
    "            if ch.islower():\n",
    "                hasLower = True\n",
    "            elif ch.isupper():\n",
    "                hasUpper = True\n",
    "            elif ch.isdigit():\n",
    "                hasDigit = True\n",
    "            elif ch in specials:\n",
    "                hasSpecial = True\n",
    "\n",
    "        return hasDigit and hasLower and hasSpecial and hasUpper "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 7:\n",
    "            return False\n",
    "        nums = set('1234567890')\n",
    "        spe = set(\"!@#$%^&*()-+\")\n",
    "        ans = [0,0,0,0,1]\n",
    "        for i in range(len(password)):\n",
    "            ordi = ord(password[i])\n",
    "            if i != 0 and password[i] == last:\n",
    "                ans[4] = 0\n",
    "            if 97<=ordi<=124:\n",
    "                ans[0] = 1\n",
    "            elif 65<=ordi<=91:\n",
    "                ans[1] = 1\n",
    "            elif password[i] in nums:\n",
    "                ans[2] = 1\n",
    "            elif password[i] in spe:\n",
    "                ans[3] = 1\n",
    "            last = password[i]\n",
    "        return ans == [1,1,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "            d = []\n",
    "            if len(password) < 8:\n",
    "                return False\n",
    "\n",
    "            # while i <= length - 2:\n",
    "            #     if str[i] == str[i + 1]:\n",
    "            #         return False\n",
    "            #     else:\n",
    "            #         i += 1\n",
    "            s1 = ''\n",
    "            for s in password:\n",
    "                if s == s1:\n",
    "                    return False\n",
    "                else:\n",
    "                    s1 = s\n",
    "\n",
    "                # if len(d) == 4:\n",
    "                #     return True\n",
    "                # else:\n",
    "                #     pass\n",
    "\n",
    "                if s.isupper() and 'u' not in d:\n",
    "                    d.append('u')\n",
    "                elif s.islower() and 'l' not in d:\n",
    "                    d.append('l')\n",
    "                elif s.isdigit() and 'd' not in d:\n",
    "                    d.append('d')\n",
    "                elif s in '!@#$%^&*()-+' and 'c' not in d:\n",
    "                    d.append('c')\n",
    "\n",
    "            if len(d) < 4:\n",
    "                return False\n",
    "            else:\n",
    "                return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        for i in range(1,len(password)):\n",
    "            if password[i] == password[i-1]:\n",
    "                return False\n",
    "        f1,f2,f3,f4 = False,False,False,False\n",
    "        for i in range(len(password)):\n",
    "            if ord(password[i]) >= 65 and ord(password[i]) <= 90:\n",
    "                f1 = True\n",
    "            if ord(password[i]) >= 97 and ord(password[i]) <= 122:\n",
    "                f2 = True\n",
    "            if password[i] in '0123456789':\n",
    "                f3 = True\n",
    "            if password[i] in '!@#$%^&*()-+':\n",
    "                f4 = True\n",
    "        return f1&f2&f3&f4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        ans = 0\n",
    "        special_word = \"!@#$%^&*()-+\"\n",
    "        n = len(password)\n",
    "        if n < 8: return False\n",
    "        for i in range(n):\n",
    "            if i + 1 < n and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            if 'a' <= password[i] <= 'z':\n",
    "                ans |= 1\n",
    "            elif 'A' <= password[i] <= 'Z':\n",
    "                ans |= 1 << 1\n",
    "            elif '0' <= password[i] <= '9':\n",
    "                ans |= 1 << 2\n",
    "            elif password[i] in special_word:\n",
    "                ans |= 1 << 3\n",
    "        \n",
    "        return ans == 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        judge = {'l':0,'u':0,'d':0,'t':0}\n",
    "        for i in range(len(password)):\n",
    "            if i != 0 and password[i] == password[i-1]:\n",
    "                return False\n",
    "            if password[i].isalpha():\n",
    "                if password[i].islower():\n",
    "                    judge['l'] += 1\n",
    "                else:\n",
    "                    judge['u'] += 1\n",
    "            elif password[i].isdigit():\n",
    "                judge['d'] += 1\n",
    "            else:\n",
    "                judge['t'] += 1\n",
    "        for v in judge.values():\n",
    "            if v == 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        return  bool(len(password) >= 8 and\n",
    "                search(r'\\d', password) and\n",
    "                search(r'[a-z]', password) and\n",
    "                search(r'[A-Z]', password) and\n",
    "                search(r'[-!@#$%^&*()+]', password) and\n",
    "                not search(r'(.)\\1', password))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        return  bool(len(password) >= 8 and\n",
    "                search(r'\\d', password) and\n",
    "                search(r'[a-z]', password) and\n",
    "                search(r'[A-Z]', password) and\n",
    "                search(r'[!@#$%^&*()\\-+]', password) and\n",
    "                not search(r'(.)\\1', password))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password)<8:\n",
    "            return False\n",
    "        for i in range(len(password)-1):\n",
    "            if password[i]==password[i+1]:\n",
    "                return False\n",
    "        s=set(password)\n",
    "        return s&set('1234567890')!=set() and s&set('QWERTYUIOPASDFGHJKLZXCVBNM')!=set() and s&set('qwertyuiopasdfghjklzxcvbnm')!=set() and s&set('!@#$%^&*()-+')!=set()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        chars = \"!@#$%^&*()-+\"\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        a, b, c, d = 0, 0, 0, 0\n",
    "        for i in range(n):\n",
    "            if password[i].islower():\n",
    "                a += 1\n",
    "            elif password[i].isupper():\n",
    "                b += 1\n",
    "            elif password[i].isdigit():\n",
    "                c += 1\n",
    "            elif password[i] in chars:\n",
    "                d += 1\n",
    "            if i > 0 and password[i] == password[i - 1]:\n",
    "                return False\n",
    "        if a == 0 or b == 0 or c == 0 or d == 0:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        boolean = [False]*4\n",
    "        special = {\"!\",\"@\",\"#\",\"$\",\"%\",\"^\",\"&\",\"*\",\"(\",\")\",\"-\",\"+\"}\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        for i in range(len(password)-1):\n",
    "            if password[i] == password[i+1]:\n",
    "                return False\n",
    "        for char in password:\n",
    "            if ord(char) in range(97,123):\n",
    "                boolean[0] = True\n",
    "            elif ord(char) in range(65,91):\n",
    "                boolean[1] = True\n",
    "            elif ord(char) in range(48,58):\n",
    "                boolean[2] = True\n",
    "            elif char in special:\n",
    "                boolean[3] = True\n",
    "        return boolean[0] and boolean[1] and boolean[2] and boolean[3]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password)<8:\n",
    "            return False\n",
    "        s=[0 for i in range(4)]\n",
    "        k='/'\n",
    "        for a in password:\n",
    "            if a.islower():\n",
    "                s[0]=1\n",
    "            if a.isupper():\n",
    "                s[1]=1\n",
    "            if a.isdigit():\n",
    "                s[2]=1\n",
    "            if a in  \"!@#$%^&*()-+\":\n",
    "                s[3]=1\n",
    "            if a==k:\n",
    "                return False\n",
    "            k=a\n",
    "        return sum(s)==4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        chars = \"!@#$%^&*()-+\"\n",
    "        lower, upper, digit, char, contin = 0, 0, 0, 0, 0\n",
    "        for i in range(n):\n",
    "            if re.match(r'^[a-z]$', password[i]):\n",
    "                lower += 1\n",
    "            if re.match(r'^[A-Z]$', password[i]):\n",
    "                upper += 1\n",
    "            if password[i].isdigit():\n",
    "                digit += 1\n",
    "            if password[i] in chars:\n",
    "                char += 1\n",
    "            if i < n-1 and password[i] == password[i+1]:\n",
    "                return False\n",
    "        return bool(lower and upper and digit and char)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "            \n",
    "        for i in range(26):\n",
    "            if chr(ord('a') + i) in password:\n",
    "                break\n",
    "            if i == 25:\n",
    "                return False\n",
    "        \n",
    "        for i in range(26):\n",
    "            if chr(ord('A') + i) in password:\n",
    "                break\n",
    "            if i == 25:\n",
    "                return False\n",
    "        \n",
    "        for c in '!@#$%^&*()-+':\n",
    "            if c in password:\n",
    "                break\n",
    "            if c == '+':\n",
    "                return False\n",
    "        \n",
    "        for c in '0123456789':\n",
    "            if c in password:\n",
    "                break\n",
    "            if c == '9':\n",
    "                return False\n",
    "        \n",
    "        for c1, c2 in zip(password, password[1:]):\n",
    "            if c1 == c2:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        nums = set('1234567890')\n",
    "        spe = set(\"!@#$%^&*()-+\")\n",
    "        s = set(password)\n",
    "        ans = [0,0,0,0,1]\n",
    "\n",
    "        for i in range(len(password)):\n",
    "            ordi = ord(password[i])\n",
    "            if i != 0 and password[i] == last:\n",
    "                ans[4] = 0\n",
    "            if 97<=ordi<=124:\n",
    "                ans[0] = 1\n",
    "            elif 65<=ordi<=91:\n",
    "                ans[1] = 1\n",
    "            elif password[i] in nums:\n",
    "                ans[2] = 1\n",
    "            elif password[i] in spe:\n",
    "                ans[3] = 1\n",
    "\n",
    "            last = password[i]\n",
    "\n",
    "        return len(password) > 7 and ans == [1,1,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        AA = '!@#$%^&*()-+'\n",
    "        if len(password) < 8:return False\n",
    "        a,b,c,d = 0,0,0,0\n",
    "        pre = '?'\n",
    "        for i in password:\n",
    "            if i == pre:return False\n",
    "            if 'a' <= i <= 'z':a = 1\n",
    "            if 'A' <= i <= 'Z':b = 1\n",
    "            if '0' <= i <= '9':c = 1\n",
    "            if i in AA:d = 1\n",
    "            pre = i\n",
    "        return bool(a and b and c and d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        # 按题意\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        specials = set(\"!@#$%^&*()-+\")\n",
    "        hasLower = hasUpper = hasDigit = hasSpecial = False\n",
    "\n",
    "        for i, ch in enumerate(password):\n",
    "            if i != len(password) - 1 and password[i] == password[i + 1]:\n",
    "                return False\n",
    "\n",
    "            if ch.islower():\n",
    "                hasLower = True\n",
    "            elif ch.isupper():\n",
    "                hasUpper = True\n",
    "            elif ch.isdigit():\n",
    "                hasDigit = True\n",
    "            elif ch in specials:\n",
    "                hasSpecial = True\n",
    "\n",
    "        return hasLower and hasUpper and hasDigit and hasSpecial\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        \"\"\"\n",
    "        小写字母 1\n",
    "        大写字母 1 << 1\n",
    "        数字 1 << 2\n",
    "        特殊字符 1 << 3\n",
    "        \"\"\"\n",
    "        ans = 0\n",
    "        special_word = \"!@#$%^&*()-+\"\n",
    "        n = len(password)\n",
    "        if n < 8:\n",
    "            return False\n",
    "        for i in range(n):\n",
    "            if i + 1 < n and password[i] == password[i + 1]:\n",
    "                return False\n",
    "            elif 'a' <= password[i] <= 'z':\n",
    "                ans |= 1\n",
    "            elif 'A' <= password[i] <= 'Z':\n",
    "                ans |= 1 << 1\n",
    "            elif '0' <= password[i] <= '9':\n",
    "                ans |= 1 << 2\n",
    "            elif password[i] in special_word:\n",
    "                ans |= 1 << 3\n",
    "        \n",
    "        return ans == 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        nums = set('1234567890')\n",
    "        spe = set(\"!@#$%^&*()-+\")\n",
    "        s = set(password)\n",
    "        lenth = lower = upper = number = special = False\n",
    "        repeat = True\n",
    "        for i in range(len(password)):\n",
    "            ordi = ord(password[i])\n",
    "            if i != 0 and password[i] == last:\n",
    "                repeat = False\n",
    "            if 97<=ordi<=124:\n",
    "                lower = True\n",
    "            elif 65<=ordi<=91:\n",
    "                upper = True\n",
    "            elif password[i] in nums:\n",
    "                number = True\n",
    "            elif password[i] in spe:\n",
    "                special = True\n",
    "\n",
    "            last = password[i]\n",
    "\n",
    "        if len(password) > 7:\n",
    "            lenth = True\n",
    "        return lenth and repeat and lower and upper and number and special"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        n = len(password)\n",
    "        if n < 8: return False\n",
    "        flag1 = flag2 = flag3 = flag4 = 0\n",
    "        for i in range(n):\n",
    "            if '0' <= password[i] <= '9': flag3 = 1\n",
    "            if 'a' <= password[i] <= 'z': flag1 = 1\n",
    "            if 'A' <= password[i] <= 'Z': flag2 = 1\n",
    "            if password[i] in \"!@#$%^&*()-+\": flag4 = 1\n",
    "            if i > 0 and password[i] == password[i-1]: return False\n",
    "            \n",
    "        return flag1 == 1 and flag2 == 1 and flag3 == 1 and flag4 == 1\n",
    "         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        if len(password) < 8:\n",
    "            return False\n",
    "        tag_status = [False, False, False, False]\n",
    "        for index, p in enumerate(password):\n",
    "            if index != 0:\n",
    "                if p == password[index - 1]:\n",
    "                    return False\n",
    "            if '0' <= p <= '9':\n",
    "                tag_status[0] = True\n",
    "            elif 'a' <= p <= 'z':\n",
    "                tag_status[1] = True\n",
    "            elif 'A' <= p <= 'Z':\n",
    "                tag_status[2] = True\n",
    "            else:\n",
    "                tag_status[3] = True\n",
    "        return all(tag_status)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def strongPasswordCheckerII(self, password: str) -> bool:\n",
    "        s = password\n",
    "        if len(s) < 8: return False\n",
    "        \n",
    "        ok = False\n",
    "        for i in range(0, 26):\n",
    "            x = chr(ord('a') + i)\n",
    "            if x in s:\n",
    "                ok = True\n",
    "                break\n",
    "        if not ok: return False\n",
    "        \n",
    "        ok = False\n",
    "        for i in range(0, 26):\n",
    "            x = chr(ord('A') + i)\n",
    "            if x in s:\n",
    "                ok = True\n",
    "                break\n",
    "        if not ok: return False\n",
    "        \n",
    "        ok = False\n",
    "        for i in range(0, 10):\n",
    "            x = chr(ord('0') + i)\n",
    "            if x in s:\n",
    "                ok = True\n",
    "                break\n",
    "        if not ok: return False\n",
    "        \n",
    "        ok = False\n",
    "        for x in \"!@#$%^&*()-+\":\n",
    "            if x in s:\n",
    "                ok = True\n",
    "                break\n",
    "        if not ok: return False\n",
    "        \n",
    "        for i in range(0, len(s) - 1):\n",
    "            if s[i] == s[i + 1]:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "           \n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
